﻿/* $RCSFile: FooterLinkEEx.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/ADNCRM.Core/UI/WebControls/FooterLinkEEx.cs $
 * $log$
 * Revision 6 2010/08/06 19:56:30  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;

using AddonNice.Diagnostics;
using AddonNice.Core;
using AddonNice.UI;
using AddonNice.UI.WebControls;
using AddonNice.Configuration;

using Trace2    =   System.Diagnostics.Trace;

namespace AddonNice.UI.WebControls
{
    [ToolboxData("<{0}:FooterLinkEEx runat=server></{0}:FooterLinkEEx>")]
    public class FooterLinkEEx : HyperLink
    {
        public enum LinkType: int {None=0,TermsOfService,Privacy,License};

        public LinkType TypeOfLink
        {
            get
            {
                object ob   =   ViewState["TypeOfLink"];
                if (ob != null )
                    return (LinkType)ob;
                return LinkType.None;
            }
            set
            {
                ViewState["TypeOfLink"] =   value;
            }
        }

        PortalSettings portalSettings
        {
            get
            {
                return (PortalSettings)HttpContext.Current.Items[StStr.strPortalSettings];
            }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            int PageID          =   0;
            switch ( TypeOfLink )
            {
                case LinkType.License:
                PageID          =   portalSettings.CustomSettings[StStr.SiteLicense].ToInt();
                break;
                case LinkType.TermsOfService:
                PageID          =   portalSettings.CustomSettings[StStr.SiteTermsOfService].ToInt();
                break;
                case LinkType.Privacy:
                PageID          =   portalSettings.CustomSettings[StStr.SiteConfidentiality].ToInt();
                break;
            }
            NavigateUrl         =   HttpUrlBuilder.BuildUrl(PageID);
            if (WebControlsTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FooterLinkEx Render TypeOfLink: {0}, NavigateUrl: {1}",TypeOfLink,NavigateUrl),WebControlsTraceSwitch.Sw.Info);
            base.Render(writer);
        }
        
        protected override void OnInit(EventArgs e)
		{
            if (WebControlsTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FooterLinkEx OnInit BEG IsUnderCRM: {0}",PortalSettings.IsUnderCRM),WebControlsTraceSwitch.Sw.Info);
            if( PortalSettings.IsUnderCRM )
                Visible =   false;
            base.OnInit(e);
            if (WebControlsTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( "[V]FooterLinkEx OnInit END.",WebControlsTraceSwitch.Sw.Info);
        }
    }
}
















